﻿using fmtx.Framework.NoSqlHelper;
using MongoDB.Driver.Builders;
using PressureTest.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace PressureTest
{
    public partial class TestResultForm : Form
    {
        MongoOperation<TestResultLog> testdb = new MongoOperation<TestResultLog>();

        public TestResultForm()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            ShowData();
        }

        private void ShowData()
        {
            var bg = Convert.ToInt32(txtbg.Text);
            var en = Convert.ToInt32(txten.Text);
            var list = testdb.Collection;
            
            if (cbxsx.Text.ToLower() == "error")
            {
                list = list.Where(w => w.StatuCode != HttpStatusCode.OK||w.IsError==true);
            }else
            if (cbxsx.Text.ToLower() == "success")
            {
                list = list.Where(w => w.StatuCode == HttpStatusCode.OK&&w.IsError==false);
            }
            if (!string.IsNullOrEmpty(txtuserId.Text))
            {
                list = list.Where(w => w.Uname==txtuserId.Text);
            }
            try
            {
                dgv.DataSource = list.OrderByDescending(o => o.ID).Skip(bg).Take(en).ToList();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        private void btngo_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void cbxsx_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowData();
        }

        private void btnrefresh_Click(object sender, EventArgs e)
        {
            ShowData();
        }
    }
}
